package br.pucrio.inf.aaaong.models.domain.database.dao.basic;

import java.sql.SQLException;

import br.pucrio.inf.aaaong.models.database.exceptions.PostgreSQLConstraintException;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryExecutor;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryParamsPreparer;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryParamsSetter;
import br.pucrio.inf.aaaong.models.domain.database.dao.basic.beans.CelularBean;

public class CelularDAO {

	private static final String QUERY_INSERT = "insert into Celular(id_adolescente, numero, responsavel) values(?,?,?)";
	private static final String QUERY_DELETE = "delete from Celular where id_adolescente = ?";
	private UpdateQueryExecutor queryExecutor;

	public CelularDAO(UpdateQueryExecutor queryExecutor) {
		this.queryExecutor = queryExecutor;
	}

	public void insert(final CelularBean celular) throws PostgreSQLConstraintException {
		queryExecutor.execute(QUERY_INSERT, new UpdateQueryParamsPreparer() {
			
			@Override
			public void prepareParameters(UpdateQueryParamsSetter params) throws SQLException {
				params.setInt(celular.getIdAdolescente());
				params.setString(celular.getNumero());
				params.setString(celular.getResponsavel());
			}
		});
	}

	public void deleteAllOfAdolescente(final int idAdolescente) throws PostgreSQLConstraintException {
		queryExecutor.execute(QUERY_DELETE, new UpdateQueryParamsPreparer() {
			
			@Override
			public void prepareParameters(UpdateQueryParamsSetter params) throws SQLException {
				params.setInt(idAdolescente);
			}
		});
	}

}
